package com.wenli.graduate2022.wenliGreenShop.repository.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wenli.graduate2022.wenliGreenShop.entity.Category;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author HuangHai
 * @date 2021/10/6 21:39
 */
@Repository
public interface CategoryMapper {

    @Select("select * from category where category_id = #{id}")
    Category findById(Integer id);

    @Select("select * from category where category_name like concat('%',#{name},'%')")
    IPage<Category> findByName(Page page,String name);

    @Select("select * from category")
    IPage<Category> findByPage(Page page);

    @Select("select * from category")
    List<Category> findAll();

    @Options(useGeneratedKeys = true, keyProperty = "categoryId",keyColumn = "category_id")
    @Insert("insert into category(category_name,category_image_src) values(#{categoryName},#{categoryImageSrc})")
    int insert(Category category);

    @Update("update category set category_name=#{categoryName},category_image_src=#{categoryImageSrc} where category_id=#{categoryId}")
    int update(Category category);

    @Delete("delete from category where category_id=#{id}")
    int delete(Integer id);

}
